package org.idea.eaglemq.broker.utils;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: LunBoWang
 * @description:
 * @date: 2025/5/8 下午7:35
 * @version: 1.0
 */
public class SpinLock implements PutMessageLock,AckMessageLock {

    AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public void lock() {
        do {
            int result = atomicInteger.getAndIncrement();
            if (result == 1) {
                return;
            }
        } while (true);
    }

    @Override
    public void unlock() {
        atomicInteger.decrementAndGet();
    }
}
